//
//  AppDelegate.m
//  大股票
//
//  Created by apple on 2019/8/14.
//  Copyright © 2019 apple. All rights reserved.
//

#import "AppDelegate.h"
//VC
#import "HHYMainTabbarC.h"
#import "RNMWKWebViewC.h"

#import "JPUSHService.h"

#import <UserNotifications/UserNotifications.h>
@interface AppDelegate ()<JPUSHRegisterDelegate>
@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    
//    // notice: 2.1.5 版本的 SDK 新增的注册方法，改成可上报 IDFA，如果没有使用 IDFA 直接传 nil
//    [JPUSHService setupWithOption:launchOptions appKey:@"15c74aa0039e6c9b07898378"
//                          channel:@"App Store"
//                 apsForProduction:YES
//            advertisingIdentifier:nil];
//    
//    
//    // Override point for customization after application launch.
//    JPUSHRegisterEntity * entity = [[JPUSHRegisterEntity alloc] init];
//    
//    entity.types = JPAuthorizationOptionAlert|JPAuthorizationOptionBadge|JPAuthorizationOptionSound;
//    
//    if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) {
//        
//        // 可以添加自定义categories
//        
//        // NSSet*categories for iOS10 or later
//        
//        // NSSet*categories for iOS8 and iOS9
//        
//    }
//    
//    [JPUSHService registerForRemoteNotificationConfig:entity delegate:self];
    
    application.statusBarStyle = UIStatusBarStyleLightContent;
    self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];
    [self.window makeKeyAndVisible];
    
    
    self.window.rootViewController = [HHYMainTabbarC new];
    
    NSString *lau = [[NSUserDefaults standardUserDefaults] objectForKey:@"AppleLanguages"][0];
    NSTimeZone * sysZone = [NSTimeZone systemTimeZone];
    
//    //4.0
//    if (([sysZone.name isEqualToString:@"Asia/Urumqi"] || [sysZone.abbreviation isEqualToString:@"GMT+8"] || [sysZone.name isEqualToString:@"Asia/Kashgar"])&& ([lau containsString:@"zh-Hant"] || [lau containsString:@"zh-Hans"])) {
//        RNMWKWebViewC *wk = [RNMWKWebViewC new];
//        __weak typeof(self)wSelf = self;
//        wk.failCallback = ^{
//            __strong typeof(self)sSelf = wSelf;
//            sSelf.window.rootViewController = [HHYMainTabbarC new];
//        };
//        self.window.rootViewController = wk;
//    }
    
    
    
    return YES;
}


- (void)applicationDidBecomeActive:(UIApplication *)application {
    [UIApplication sharedApplication].applicationIconBadgeNumber = 0;
}

#pragma mark  -  横屏
- (UIInterfaceOrientationMask )application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
//    application.statusBarHidden = NO;
//    if (_orientation) {
//        return [_orientation integerValue];
//    }
    
    return UIInterfaceOrientationMaskPortrait;
    
}

- (void)application:(UIApplication *)application

didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
    
    /// Required - 注册 DeviceToken
    
    [JPUSHService registerDeviceToken:deviceToken]; //如想获得，devicetoken直接转换成字符串即可
    
    //获得注册后的regist_id，此值一般传给后台做推送的标记用,先存储起来
    
    [[NSUserDefaults standardUserDefaults] setObject:deviceToken forKey:@"deviceToken"];
    [[NSUserDefaults standardUserDefaults] synchronize];
    
}

// 添加处理APNs通知回调方法

- (void)jpushNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(NSInteger))completionHandler {
    
    completionHandler(UNNotificationPresentationOptionAlert|UNNotificationPresentationOptionSound);
    
}
@end
